//
// Copyright (c) 2024 BPer blueskiner
//
#ifndef SRC_BPERUTIL_SRC_BPERCTIMER_H_
#define SRC_BPERUTIL_SRC_BPERCTIMER_H_
#include <bperutil/BPerType.h>
#include <stdint.h>
#include <bperutil/sys/BPerThread.h>

#if BPer_OS_APPLE
	#include <dispatch/dispatch.h>

#endif
typedef struct BPerCTimer{
	int32_t taskId;

	int32_t isStart;
	int32_t isloop;
	int32_t waitState;
	int32_t waitTime;
	bPer_thread_t threadId;
#if BPer_Enable_Timer_Phtread
	bPer_thread_mutex_t t_lock;
	bPer_thread_cond_t t_cond_mess;
#else
    #if BPer_OS_WIN
        HANDLE	hTimerQueue;
        HANDLE	hTimerQueueTimer;
        HANDLE  winEvent;
	#elif BPer_OS_APPLE
		dispatch_source_t _timer;
	#else
        int32_t timerfd;
        int32_t efd;
    #endif
#endif
	void (*doTask)(int32_t taskId,void* user);
	void* user;
}BPerCTimer;
#ifdef __cplusplus
extern "C"{
#endif
void bPer_create_timer(BPerCTimer* timer,void* user,int32_t taskId,int32_t waitTime);
void bPer_destroy_timer(BPerCTimer* timer);
void bPer_timer_start(BPerCTimer* timer);
void bPer_timer_stop(BPerCTimer* timer);
#ifdef __cplusplus
}
#endif


#endif /* SRC_BPERUTIL_SRC_BPERTIMER_H_ */
